//
// Created by Joy on 2024/7/25.
//
//希尔排序
#include <bits/stdc++.h>

using namespace std;
void ShellSort(int a[],int n){
    for(int D = n/2;D > 0;D/=2){    //D表示间隔（增量）
        for(int i = D;i < n;i++){
            int temp = a[i];
            int j ;
            for(j = i;j >= D && a[j-D] > temp;j-=D) {
                a[j] = a[j-D];
            }
            a[j] = temp;
        }
    }
}

int main() {
    int arr[8] = {6,3,17,8,0,12,8,7};
    printf("排序前：\n");
    for (int i = 0; i < 8; ++i) {
        cout << arr[i] <<" ";
    }
    int n = sizeof(arr) / sizeof(arr[0]);
    ShellSort(arr,n);
    printf("\n排序后:\n");
    for (int i = 0; i < 8; ++i) {
        cout << arr[i] <<" ";
    }
    return 0;
}
